package FilterDesigners.Butterworth;

import java.util.ArrayList;

public class LowpassButterworthFilter extends ButterworthFilter{

	public LowpassButterworthFilter(double w1, double w2, double k1, double k2) {
		super(w1, w2, k1, k2);
	}
	
	protected double calculate3dBFreq() {
		double wcPrimeExpected = W1/Math.pow(Math.pow(10.0, K1/10.0) - 1, 1.0/(2.0*ORDER));
		double wc2PrimeExpected = W2/Math.pow(Math.pow(10.0, K2/10.0) - 1, 1.0/(2.0*ORDER));
		return Math.sqrt(wcPrimeExpected*wc2PrimeExpected);
	}
	

	protected void calculateNormalizedComponents() {
		for(int i = 0; i < (ORDER - 1)*2; i++){
			if(i%2 == 0){	//Resistor values will be stored in even numbered indecies
				normalizedComponents.add(1.0);
			}
			else {	//Capacitor values will be stored in odd numbered indecies.
				if((i+1)%4 == 2)	//If this is the 1st capacitor in a four component set, it should be 2*Q.
					normalizedComponents.add(2.0*qValues.get(i/4));
				else				//If this is the 2nd capacitor in a four component set, it should be 1/(2*Q).
					normalizedComponents.add(1/(2.0*qValues.get(i/4)));
			}
		}
		if(ORDER % 2 == 1) {	//If the filter order is odd, tack on a passive section (R = 1, C = 1)
			normalizedComponents.add(1.0);
			normalizedComponents.add(1.0);
		}
			
		
	}

}
